#include "DXGIFactory.hpp"
#include "D3D12CommandQueue.hpp"
#include "DXGISwapChain.hpp"
using namespace NAMESPACENAME::DirectX;
DXGIAdapter* DXGIFactory::EnumAdapters(UINT Adapter)const
{
	IDXGIAdapter1* adap1;
	IDXGIAdapter4* adap4;
	if (FAILED(factory->EnumAdapters1(Adapter, &adap1)))
		return nullptr;
	if (FAILED(adap1->QueryInterface(&adap4)))
	{
		adap1->Release();
		return nullptr;
	}
	adap1->Release();
	return new DXGIAdapter(adap4);
}
DXGIFactory::~DXGIFactory()
{
	factory->Release();
}
DXGISwapChain* DXGIFactory::CreateSwapChain(
	D3D12CommandQueue* commandQueue,
	NAMESPACENAME::DirectXViewerControl* viewer,
	const DXGI_SWAP_CHAIN_DESC1* pDesc,
	const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullScreenDesc,
	IDXGIOutput* pRestrictToOutput
)const
{
	if (IDXGISwapChain1* chain1; SUCCEEDED(factory->CreateSwapChainForHwnd(commandQueue->commandQueue, viewer->WindowHandle(), pDesc, pFullScreenDesc, pRestrictToOutput, &chain1)))
		if (IDXGISwapChain4* chain4; SUCCEEDED(chain1->QueryInterface(&chain4)))
		{
			chain1->Release();
			return new DXGISwapChain(chain4);
		}
		else
			chain1->Release();
	return nullptr;
}